package finalproject.model.items;

import java.util.List;

import finalproject.config.Ressource;
import finalproject.model.player.Player;
import finalproject.model.player.PlayerModel;
import finalproject.model.rooms.Room; 
import finalproject.view.StringManager;
/**
 * The map item
 * When used, list the rooms, and display where are the other players
 * @author Shafiq Daniel
 *
 */
/**
 * A map is an item that can be used by a player to see all the rooms
 * in the current game, and the player in each room * 
 * 
 * @author Shafiq Daniel
 */

public class Map extends Item
{	
	/**
	 * the player list
	 */
	private List<Player> playerList;
	/**
	 * The room list
	 */
	private List<Room> roomList;
	/**
	 * The amount of energy needed to use the item
	 */
	private static final int ENERGY_TO_USE = 4;

	public Map() {
		super(StringManager.getString("map"), StringManager.getString("mapdescription"), 1, true, false, false);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void use(Player player) {
		// TODO Auto-generated method stub
		playerList = PlayerModel.getInstance().getPlayers();
		roomList = Ressource.getRoomList();	// TODO : check if we can do this by using Mapper
		if(player.getEnergy().getEnergy()>ENERGY_TO_USE)
			StringManager.outPutText(showPlayerAndRoom());		
	}
	
	/**
	 * @return a description of the game context, with the player and their positions
	 */
	private String showPlayerAndRoom(){
		String listPlayerAndRoom = "";
		
		for(int i=0;i<roomList.size();i++){
			listPlayerAndRoom = listPlayerAndRoom + roomList.get(i).getShortDescription() +  "\t" + 
								checkPlayerInRoom(roomList.get(i))  + "\n";
		}		
		return listPlayerAndRoom;		
	}
	
	/**
	 * Check which player is in a room
	 * @param room the room to check
	 * @return the player inside the room if there is one, else it returns the empty string ""
	 */
	private String checkPlayerInRoom(Room room){
		String players="";
		
		for(int i=0;i<playerList.size();i++){
			if(playerList.get(i).getCurrentRoom().equals(room))
				players = players + playerList.get(i).getNickname() + ",";
		}
		return players;
	}
	


}
